﻿@model SalesPortal.Web.Models.EmployeeListingViewModel

@{
    ViewBag.Title = "Employee Listing";
}

<h2>Employee Listing</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>

@*<div class="container">
    <div class="row">
        <div class="col-md-8"></div>
        <div class="col-md-4">&nbsp;</div>
    </div>&nbsp;
</div>*@


@*<button type="button" class="btn btn-default" data-toggle="modal" data-target="#filterRecordsModal">
    <span class="glyphicon glyphicon-filter"></span> filter records
</button>*@

@*<div>
    <a href="#" class="btn btn-link">Prev</a>
    <a href="#" class="btn btn-link">Next</a>
    |
    <a tabindex="0" class="btn btn-link" id="example"
       role="button" data-toggle="popover" 
       data-trigger="focus" title="Dismissible popover" 
       data-content="And here's some amazing content. It's very engaging. Right?">Page(s)</a>:
    <a href="#" class="btn btn-link">1</a>
    <a href="#" class="btn btn-link">2</a>
    <a href="#" class="btn btn-link">3</a>
    <a href="#" class="btn btn-link">4</a>
    <a href="#" class="btn btn-link">5</a>
</div>*@











<nav class="navbar navbar-inverse navbar-default">
    <div class="container-fluid">
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">

                @if (Model.TablePager.PrevPageNo > 0)
                {
                    <li>
                        <a href="@Url.Action("Index", new { p = Model.TablePager.PrevPageNo })"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> PREV </a>
                    </li>
                }
                else
                {
                    <li>
                        <a class="disabled"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> PREV <span class="sr-only">(current)</span></a>
                    </li>
                }

                @if (Model.TablePager.NextPageNo < Model.TablePager.TotalNumberOfPages)
                {
                    <li>
                        <a href="@Url.Action("Index", new { p = Model.TablePager.NextPageNo })"> NEXT <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></a>
                    </li>
                }
                else
                {
                    <li>
                        <a class="disabled"> NEXT <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></a>
                    </li>
                }

                <li>
                    <p>&nbsp;&nbsp;&nbsp;&nbsp;</p>
                </li>

                @*<li class="active"><a href="#">01</a></li>
                    <li><a href="#">02</a></li>
                    <li><a href="#">03</a></li>
                    <li><a href="#">04</a></li>
                    <li><a href="#">05</a></li>*@

                @foreach (int num in Model.TablePager.RelatedPages)
                {
                    if (num == Model.TablePager.CurrentPageNo)
                    {
                        <li class="active"><a>@num.ToString("00")</a></li>
                    }
                    else
                    {
                        @*<li><a href="@Url.Action("Index", new { p = @num })">@num.ToString("00")</a></li>*@
                        <li>
                            <a style="cursor:pointer;" onclick="goToPage(@num)">@num.ToString("00")</a>
                        </li>
                    }
                }

                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Page Size <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">10 records per page</a></li>
                        <li class="active"><a href="#">25 records per page</a></li>
                        <li><a href="#">50 records per page</a></li>
                    </ul>
                </li>
            </ul>

            <ul class="nav navbar-nav navbar-right">
                <li>
                    <button type="button" class="btn btn-primary navbar-btn btn-link" data-toggle="modal" data-target="#filterRecordsModal">
                        <span class="glyphicon glyphicon-filter"></span> filter records
                    </button>
                </li>
            </ul>
            @*<form class="navbar-form navbar-right" role="search">
                    <div class="form-group">
                        <input type="text" class="form-control page-input" placeholder="page#">
                    </div>
                    <button type="submit" class="btn btn-primary navbar-form-btn btn-xs"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>  Go</button>
                </form>*@

            @using (Html.BeginForm("Index", "Employee", FormMethod.Post, new { @class = "navbar-form navbar-right", role = "search", id = "pagejump_form" }))
            {
                <div class="form-group">
                    @*<input type="text" class="form-control page-input" placeholder="page#">*@
                    @Html.TextBox("p", string.Empty, new { @class = "form-control page-input text-center", placeholder = "page#", id = "pageNo" })
                </div>

                <button type="submit" class="btn btn-primary navbar-form-btn btn-xs"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> Go </button>
            }
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

@*@Html.Partial("_PagerNavBarPartial")*@

<!-- Modal -->
<div class="modal fade" id="filterRecordsModal" tabindex="-1" role="dialog" aria-labelledby="filterRecordsModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Filter Employee</h4>
            </div>
            <div class="modal-body">
                @using (Html.BeginForm("Index", "Employee", FormMethod.Post, new { @class = "form-horizontal" }))
                {
                    @Html.EditorFor(m => m.Filter)
                }
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

@*@Html.DisplayFor(m => m.EmployeeList)*@

<table class="table table-striped table-hover table-condensed" id="employeeList">
    <thead>
        <tr>
            <th class="col-md-1">
                Legal Name
            </th>
            <th class="col-md-1 nowrap">
                Date of Birth
            </th>
            <th class="col-md-1">
                Salary
            </th>
            <th class="col-md-1">
                Status
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>



    </tbody>
</table>

@section scripts
{
<script type="text/javascript" src="~/Scripts/employee.js"></script>

<script type="text/javascript">

    function clearEmployeeFilterForm() {
        $("#Filter_LegalName").val("");                                     //Clear Full Name
        $("#Filter_StartDateOfBirth").data("kendoDatePicker").value(null);  //Clear Date of Birth (from)
        $("#Filter_EndDateOfBirth").data("kendoDatePicker").value(null);    //Clear Date of Birth (to)
        $("#Filter_StartSalary").data("kendoNumericTextBox").value(null);   //Clear Salary (from)
        $("#Filter_EndSalary").data("kendoNumericTextBox").value(null);     //Clear Salary (to)
        $("#Filter_Status").data("kendoDropDownList").value(null);          //Reset Status
    }

    function goToPage(pageNum)
    {
        $("#pagejump_form #pageNo").val(pageNum);
        $("#pagejump_form").submit();
    }

    $(document).ready(function () {
        jQuery.support.cors = true;
        $.ajax({
            url: 'http://dev.sales.web/api/Employee',
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                debugger;
                var $tbody = $("table#employeeList tbody"), rec, html = [];

                html.push("<tr>");                                                      //00
                html.push("    <td class=\"nowrap\">");                                 //01
                html.push("        Ann King");                                          //02
                html.push("    </td>");                                                 //03
                html.push("    <td>");                                                  //04
                html.push("        1993-03-02");                                        //05
                html.push("    </td>");                                                 //06
                html.push("    <td>");                                                  //07
                html.push("        $7,294.04");                                         //08
                html.push("    </td>");                                                 //09
                html.push("    <td>");                                                  //10
                html.push("        <span>Employed</span>");                             //11
                html.push("    </td>");                                                 //12
                html.push("    <td>");                                                  //13
                html.push("        <a href=\"/employee/Edit/20\">Edit</a> |");          //14
                html.push("        <a href=\"/employee/Details/20\">Details</a> |");    //15
                html.push("        <a href=\"/employee/Delete/20\">Delete</a>");        //16
                html.push("    </td>");                                                 //17
                html.push("</tr>");                                                     //18

                for (rec in data) {
                    html[2] = data[rec].LegalName;
                    html[6] = data[rec].DateOfBirth;
                    html[8] = data[rec].Salary;
                    html[11] = data[rec].Status;

                    html[14] = "<a href=\"/employee/Edit/" + data[rec].Id + "\">Edit</a> |";
                    html[15] = "<a href=\"/employee/Details/" + data[rec].Id + "\">Details</a> |";
                    html[16] = "<a href=\"/employee/Delete/" + data[rec].Id + "\">Delete</a>";

                    $tbody.append(html.join(""));
                }
            },
            error: function (x, y, z) {
                alert(x + '\n' + y + '\n' + z);
            }
        });
    });

</script>
}